package client;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.rmi.*;

import transaction.InvalidTransactionException;
import transaction.TransactionAbortedException;
import transaction.WorkflowController;

public class Client2 {
	public static void main(String [] args) throws IOException, NotBoundException {
		Properties prop = new Properties();
		prop.load(new FileInputStream("conf/ddb.conf"));
//		String wcport = prop.getProperty("8081");

		WorkflowController wc = (WorkflowController) Naming.lookup(WorkflowController.RMIName);
		int xid = wc.start();
		try {
//			wc.deleteFlight(xid, "NO1");
//			wc.deleteRooms(xid, "Shanghai", 10);
			wc.deleteCars(xid, "Shanghai", 300);
		} catch (TransactionAbortedException | InvalidTransactionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			wc.commit(xid);
		} catch (TransactionAbortedException | InvalidTransactionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		int numAvail = -1;
		try{
			xid = wc.start();
//			numAvail = wc.queryFlight(xid, "NO1");
			numAvail = wc.queryCars(xid, "Shanghai");
			wc.commit(xid);
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println("num avail of NO1 is :"+numAvail);
	}
}